//
//  IdCardViewController.m
//  Fangmm
//
//  Created by 阮琦 on 16/3/4.
//  Copyright © 2016年 com.fangmm. All rights reserved.
//

#import "IdCardViewController.h"
#import "ACMacros.h"

#import "User.h"
#import <MobClick.h>

@interface IdCardViewController ()

@end

@implementation IdCardViewController {

    __weak IBOutlet UITextField *fullNameTextField;
    __weak IBOutlet UITextField *IdCardTextField;
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"IDcard页"];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"IDcard页"];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self configureNavigationBar];
    if (!([[User sharedUser].identityCard isEqual:@"未完善"] || [User sharedUser].identityCard == nil)) {
        [IdCardTextField setText:[User sharedUser].identityCard];
    }
    if (!([[User sharedUser].fullName isEqual:@"未完善"] || [User sharedUser].fullName == nil)) {
        [fullNameTextField setText:[User sharedUser].fullName];
    }

    
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark - Configuring the view’s layout behavior
- (void)configureNavigationBar {
    self.title = @"身份证";
    self.navigationItem.hidesBackButton = true;
    UIImage *backImage = [[UIImage imageNamed:@"back-18-36"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc]initWithImage:backImage style:UIBarButtonItemStyleDone target:self action:@selector(clickToPopBack)];
    self.navigationItem.leftBarButtonItem = leftBarButton;
    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(clickToDone)];
    [rightBarButton setTintColor:RGBACOLOR(119, 119, 119, 1)];
    self.navigationItem.rightBarButtonItem = rightBarButton;
}

#pragma mark - Triggering Methods
- (void)clickToPopBack {
    [IdCardTextField resignFirstResponder];
    [fullNameTextField resignFirstResponder];
//    [User sharedUser].identityCard = IdCardTextField.text;
//    [User sharedUser].fullName = fullNameTextField.text;
    [self.navigationController popViewControllerAnimated:true];
}

- (void)clickToDone {
    [IdCardTextField resignFirstResponder];
    [fullNameTextField resignFirstResponder];
    [User sharedUser].identityCard = IdCardTextField.text;
    [User sharedUser].fullName = fullNameTextField.text;
    [self.navigationController popViewControllerAnimated:true];
}

@end
